package fun.werfamily.wf.order.core.controller;

import fun.werfamily.wf.base.vo.PageInfo;
import fun.werfamily.wf.base.vo.Result;
import fun.werfamily.wf.order.core.domain.dto.req.OrderConfirmReqDTO;
import fun.werfamily.wf.order.core.domain.dto.req.OrderListReqDTO;
import fun.werfamily.wf.order.core.domain.dto.req.OrderReqDTO;
import fun.werfamily.wf.order.core.domain.dto.req.OrderSubmitReqDTO;
import fun.werfamily.wf.order.core.domain.dto.result.OrderCancelDTO;
import fun.werfamily.wf.order.core.domain.dto.result.OrderDTO;
import fun.werfamily.wf.order.core.domain.dto.result.OrderListDTO;
import fun.werfamily.wf.order.core.domain.dto.result.OrderStatisticsDTO;
import fun.werfamily.wf.order.core.domain.service.OrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * Created with IntelliJ IDEA.
 *
 * @Author: Mr.WenMing Zhang
 * @Date: 2022-08-28 11:31
 * @Description:
 */

@Api(tags = "订单模块")
@RequestMapping("/order")
@RestController
public class OrderController {

    @Resource
    private OrderService orderService;

    @ApiOperation("预创建订单")
    @PostMapping("/confirm")
    public Result<OrderDTO> orderConfirm(@Valid @RequestBody OrderConfirmReqDTO orderConfirmReqDTO) {
        return Result.success(orderService.orderConfirm(orderConfirmReqDTO));
    }

    @ApiOperation("提交订单")
    @PostMapping("/submit")
    public Result<OrderDTO> orderSubmit(@RequestBody OrderSubmitReqDTO orderSubmitReqDTO) {
        return Result.success(orderService.orderSubmit(orderSubmitReqDTO));
    }

    @ApiOperation("创建订单")
    @PostMapping("/create")
    public Result<OrderDTO> orderCreate(@Valid @RequestBody OrderConfirmReqDTO orderConfirmReqDTO) {
        return Result.success(orderService.orderCreate(orderConfirmReqDTO));
    }

    @ApiOperation("订单详情")
    @PostMapping("/detail")
    public Result<OrderDTO> orderInfo(@RequestBody OrderReqDTO orderReqDTO) {
        return Result.success(orderService.orderInfo(orderReqDTO));
    }

    @ApiOperation("查询支付结果")
    @PostMapping("/payResult")
    public Result<Boolean> payResult(@RequestBody OrderReqDTO orderReqDTO) {
        return Result.success(Boolean.TRUE);
    }

    @ApiOperation("取消订单")
    @PostMapping("/cancel")
    public Result<OrderCancelDTO> cancelOrder(@RequestBody OrderReqDTO orderReqDTO) {
        return Result.success(orderService.cancelOrder(orderReqDTO));
    }

    @ApiOperation("订单列表")
    @PostMapping("/list")
    public Result<PageInfo<OrderListDTO>> orderList(@RequestBody OrderListReqDTO orderListReqDTO) {
        return Result.success(orderService.orderList(orderListReqDTO));
    }

    @ApiOperation("订单统计")
    @GetMapping("/statistics")
    public Result<OrderStatisticsDTO> orderCount(){
        return Result.success(orderService.orderCount());
    }
}
